package com.dragonwu.service.impl;

import com.dragonwu.entity.SysMenu;
import com.dragonwu.mapper.SysMenuMapper;
import com.dragonwu.service.ISysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragonwu.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统菜单 服务实现类
 * </p>
 *
 * @author DragonWu
 * @since 2022-10-11
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {

    @Autowired
    private ISysRoleService sysRoleService;

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Override
    public List<SysMenu> getMenuByUserId(Long userId) {
        //1、如果该用户是超级管理员-->拥有所有的菜单
        if(sysRoleService.isSuperAdmin(userId)){
            return list();//查询所有
        }
        //2、如果该用户部署超级管理员-->查询角色-->查询菜单
        return sysMenuMapper.selectMenusByUserId(userId);
    }
}
